﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Sales_SaleAchievementDetailSrh
 * 类型：       控制层
 * 功能说明：   员工业绩明细检索页面
 * 作者：       黄鑫
 * 创建日期：   2007/09/17
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using log4net;
using Shpm.App.Search.Bean;
using Shpm.App.Search.Dao;
using Shpm.App.Master.Bean;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Commons.Utils;

public partial class SaleAchievementDetailSrhForm : System.Web.UI.Page
{
    protected static ILog log = LogManager.GetLogger(typeof(SaleAchievementDetailSrhForm));
    private const string COMMAND_SEARCH = "DoSearch";
    private const string BEGIN_DATE = "1900/01/01";
    private const string END_DATE = "2999/12/31";

    //Form Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            // 接收传递参数并初始化控件
            lblEmployeeId.Text = Convert.ToString(Context.Items["EmployeeId"]);
            lblBeginDate.Text = Convert.ToString(Context.Items["ParamBeginDate"]);
            lblEndDate.Text = Convert.ToString(Context.Items["ParamEndDate"]);

            // 接收传递参数为检索条件
            ViewState["EmployeeId"] = Convert.ToString(Context.Items["EmployeeId"]);
            ViewState["ParamEmployeeId"] = Convert.ToString(Context.Items["ParamEmployeeId"]);
            ViewState["ParamBeginDate"] = Convert.ToString(Context.Items["ParamBeginDate"]);
            ViewState["ParamEndDate"] = Convert.ToString(Context.Items["ParamEndDate"]);
            ViewState["ParamPageIndex"] = Convert.ToString(Context.Items["ParamPageIndex"]);
            ViewState["ParamIsEmptyDate"] = Convert.ToString(Context.Items["ParamIsEmptyDate"]);
        }

    }

    // Step Click
    protected void viewSrhRst_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    }

    // page index change
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        SaleAchievementDetailSrhBean dataBean = new SaleAchievementDetailSrhBean();

        dataBean.EmployeeId = string.IsNullOrEmpty(Convert.ToString(ViewState["EmployeeId"])) ? null:Convert.ToString(ViewState["EmployeeId"]);
        dataBean.BeginDate = string.IsNullOrEmpty(Convert.ToString(ViewState["ParamBeginDate"])) ? BEGIN_DATE : Convert.ToString(ViewState["ParamBeginDate"]);
        dataBean.EndDate = string.IsNullOrEmpty(Convert.ToString(ViewState["ParamEndDate"])) ? END_DATE : Convert.ToString(ViewState["ParamEndDate"]);
        SaleAchievementDetailSrhDao dao = new SaleAchievementDetailSrhDao();
        IList dataList = dao.ListAchievementDetailSrh(dataBean);
        viewSrhRst.DataSource = dataList;
        if (dataList.Count == 0)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0005").ToString();
            tblResult.Visible = false;
        }
        else
        {
            tblResult.Visible = true;
        }
        viewSrhRst.DataBind();

    }

    // adjust bind data
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "~/App/Search/SaleAchievementSrhForm.aspx";   
        // 传递分页编号
        Context.Items["ParamEmployeeId"] = ViewState["ParamEmployeeId"];
        Context.Items["ParamBeginDate"] = ViewState["ParamBeginDate"];
        Context.Items["ParamEndDate"] = ViewState["ParamEndDate"];
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
        Context.Items["ParamIsEmptyDate"] = "1";
        ControllerUtils.Transfer(Context, url, true);  
    }
}
